flask中models定义表名时最好用小写字母

class Employee(db.Model, BaseDbModel):
id = db.Column(db.Integer, autoincrement=True, primary_key=True)
name = db.Column(db.String(30), nullable=False)
address = db.Column(db.String(100), nullable=True)
phone = db.Column(db.String(300), nullable=True)
post =db.Column(db.String(50), nullable=True)
note = db.Column(db.String(200), nullable=True)
company_id = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=False)

__tablename__ = 'employee' # 如果大写,通过flask-migrate迁移进mysql还是小写的表名,如果再次迁移,会因表名不同,而重复操作报错。

def __init__(self, name):
self.name = name




常用操作命令:

python manage.py db migrate
python manage.py db upgrade
python manage.py runserver 或 python manage.py runsrever -h 192.168.2.13 -p 8080
posted @ 2019-10-26 08:22  seawind2012  阅读(332)  评论(0编辑  收藏  举报